fn main() {
    println!("Hello, world!");
    let nums1 = vec!(1, 2, 3);
    let nums2 = vec!(4, 5, 6);
    let res = Solution::find_median_sorted_arrays(nums1, nums2);
    println!("{}", res)
}

struct Solution;

impl Solution {
    pub fn find_median_sorted_arrays(nums1: Vec<i32>, nums2: Vec<i32>) -> f64 {
        let mut n1 = if nums1.len() >= nums2.len() { &nums1 } else { &nums2 };
        let mut n2 = if nums1.len() < nums2.len() { &nums1 } else { &nums2 };
        let mut res: f64 = 0 as f64;
        let total_length: usize = n1.len() + n2.len();
        let (mut i, mut j) = (0 as usize, 0 as usize);
        while i < n1.len() || j < n2.len() {
            let next_val: f64 =
                if j == n2.len() || (i != n1.len() && n1[i] < n2[j]) { n1[i] as f64 } else { n2[j] as f64 };
            if (i + j) * 2 == (total_length) {
                return (res + next_val) / 2 as f64;
            } else if (i + j) * 2 > (total_length) {
                return res;
            } else {
                res = next_val;
                if j == n2.len() || (i != n1.len() && n1[i] < n2[j]) { i = i + 1; } else { j = j + 1; };
            }
        }
        res
    }
}